package com.pomelo.base.core.bean;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * 数据库表元素信息
 *
 * @author biankudingcha
 * @date: 2021-07-23
 * @since 0.5.0
 */
public class TableMetaData implements java.io.Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 表名称
     */
    private String tableName;

    /**
     * 表注释
     */
    private String tableRemarks;

    /**
     * 主键
     */
    private String primaryKey;

    /**
     * 索引
     */
    private List<TableIndexInfo> index = new ArrayList<TableIndexInfo>();

    /**
     * 
     * /** 列信息
     */
    private Map<String, ColumnMetaData> columnMap = null;

    public TableMetaData(String tableName, String tableRemarks, String primaryKey, List<TableIndexInfo> index,
            Map<String, ColumnMetaData> columnMap) {
        this.tableName = tableName;
        this.tableRemarks = tableRemarks;
        this.primaryKey = primaryKey;
        this.index = index;
        if (index != null && !index.isEmpty()) {
            List<TableIndexInfo> unmodifiableList = Collections.unmodifiableList(index);
            this.index = unmodifiableList;
        }
        if (columnMap != null && !columnMap.isEmpty()) {
            Map<String, ColumnMetaData> unmodifiableMap = Collections.unmodifiableMap(columnMap);
            this.columnMap = unmodifiableMap;
        }
    }

    /**
     * 获取表名称
     *
     * @return String
     */
    public String getTableName() {
        return tableName;
    }

    /**
     * 表说明
     *
     * @return String
     */
    public String getTableRemarks() {
        return tableRemarks;
    }

    /**
     * 主键
     *
     * @return String
     */
    public String getPrimaryKey() {
        return primaryKey;
    }

    /**
     * 表的索引
     *
     * @return List
     */
    public List<TableIndexInfo> getIndex() {
        return index;
    }

    /**
     * 列信息
     *
     * @return Map
     */
    public Map<String, ColumnMetaData> getColumnMap() {
        return columnMap;
    }

    /**
     * 是否存在列
     *
     * @param columnName 列名称
     * @return boolean
     */
    @Deprecated
    public boolean isColumn(String columnName) {
        return columnMap.containsKey(columnName);
    }
    
    /**
     * 是否存在列
     *
     * @param columnName 列名称
     * @return boolean
     */
    public boolean existsColumn(String columnName) {
        return columnMap.containsKey(columnName);
    }
}
